﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Bymed.SpineScan.WPF.Model;
using Bymed.SpineScan.WPF.ViewModel.TestItemViewModel;
using Bymed.SpineScan.DataModel;
using Bymed.SpineScan.WPF.Shared;

namespace Bymed.SpineScan.WPF.ViewModel
{
    public class AllTestResultsViewModel : AllTestItemsViewModel
    {
        public const string ShowTestSummaryReportMessageToken = "AllTestResultsShowTestSummaryReportMessage";
        public const string ShowSingleTestDetailMessageToken = "AllTestResultsShowSingleTestDetailMessage";
        public IEnumerable<DiagnosticMessageReference> DiagnosticMessageList { get; set; }
        public string TestTimestamp { get; set; }
        public string AttachedDiagnosticMessage { get; set; }

        /// <summary>
        /// Initializes a new instance of the AllTestResultsViewModel class.
        /// </summary>
        public AllTestResultsViewModel(IDataService dataService)
            : base(dataService) { }

        /// <summary>
        /// The <see cref="IsSelected" /> property's name.
        /// </summary>
        public const string IsSelectedPropertyName = "IsSelected";

        private bool _isSelected = false;

        /// <summary>
        /// Sets and gets the IsSelected property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public bool IsSelected
        {
            get
            {
                return _isSelected;
            }

            set
            {
                if (_isSelected == value)
                {
                    return;
                }

                RaisePropertyChanging(IsSelectedPropertyName);
                _isSelected = value;
                RaisePropertyChanged(IsSelectedPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="TestDateDisplay" /> property's name.
        /// </summary>
        public const string TestDateDisplayPropertyName = "TestDateDisplay";

        private string _testDateDisplay = string.Empty;

        /// <summary>
        /// Sets and gets the TestDateDisplay property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string TestDateDisplay
        {
            get
            {
                return _testDateDisplay;
            }

            set
            {
                if (_testDateDisplay == value)
                {
                    return;
                }

                RaisePropertyChanging(TestDateDisplayPropertyName);
                _testDateDisplay = value;
                RaisePropertyChanged(TestDateDisplayPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="SequenceNumber" /> property's name.
        /// </summary>
        public const string SequenceNumberPropertyName = "SequenceNumber";

        private int _sequenceNumber = 0;

        /// <summary>
        /// Sets and gets the SequenceNumber property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public int SequenceNumber
        {
            get
            {
                return _sequenceNumber;
            }

            set
            {
                if (_sequenceNumber == value)
                {
                    return;
                }

                RaisePropertyChanging(SequenceNumberPropertyName);
                _sequenceNumber = value;
                RaisePropertyChanged(SequenceNumberPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="AttendingDoctor" /> property's name.
        /// </summary>
        public const string AttendingDoctorPropertyName = "AttendingDoctor";

        private AttendingDoctor _attendingDoctor = null;

        /// <summary>
        /// Sets and gets the AttendingDoctor property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public AttendingDoctor AttendingDoctor
        {
            get
            {
                return _attendingDoctor;
            }

            set
            {
                if (_attendingDoctor == value)
                {
                    return;
                }

                RaisePropertyChanging(AttendingDoctorPropertyName);
                _attendingDoctor = value;
                RaisePropertyChanged(AttendingDoctorPropertyName);
            }
        }

        private RelayCommand _showTestSummaryReportCommand;

        /// <summary>
        /// Gets the ShowTestSummaryReportCommand.
        /// </summary>
        public RelayCommand ShowTestSummaryReportCommand
        {
            get
            {
                return _showTestSummaryReportCommand
                    ?? (_showTestSummaryReportCommand = new RelayCommand(
                                          () =>
                                          {
                                              // Generate TestItemList & Send to PatientDataSearchPage, request to show the selected test result report.
                                              Messenger.Default.Send<AllTestResultsViewModel>(this, AllTestResultsViewModel.ShowTestSummaryReportMessageToken);
                                          }));
            }
        }

        private RelayCommand<SingleTestItemViewModel> _showSingleTestDetailCommand;

        /// <summary>
        /// Gets the ShowHistoryDataAnalysisReport.
        /// </summary>
        public RelayCommand<SingleTestItemViewModel> ShowSingleTestDetailCommand
        {
            get
            {
                return _showSingleTestDetailCommand
                    ?? (_showSingleTestDetailCommand = new RelayCommand<SingleTestItemViewModel>(
                                          p =>
                                          {
                                              // Send to PatientDataSearchPage & TestSummaryPage, request to show the selected test detail page.
                                              Messenger.Default.Send<SingleTestItemViewModel>(p, AllTestResultsViewModel.ShowSingleTestDetailMessageToken);
                                          }));
            }
        }
    }
}
